package utils

import (
	"bytes"
	"encoding/binary"

	"github.com/sigurn/crc16"
)

func WriteChecksum(buf *bytes.Buffer, order binary.ByteOrder) {
	table := crc16.MakeTable(crc16.CRC16_KERMIT)
	checksum := crc16.Checksum(buf.Bytes(), table)
	binary.Write(buf, order, checksum)
}

func CrcSum(buf []byte) uint16 {
	table := crc16.MakeTable(crc16.CRC16_KERMIT)
	return crc16.Checksum(buf, table)
}
